<!-- 
 *  Copyright [2014] UW-Parkside
 * Authors: Jasmine Griffiths, Matthew Zygowicz, Armando Narvaez
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
*/
-->

<!-- 'editroute.php' This is the page to edit routes in the table/database-->
<body>
    <?php
    if (strlen($errMsg) > 0) {//Display error message if there is one
        print "<div class='alert-box error'>";
        print "<strong>Error!</strong>";
        print "<p>";
        print $errMsg;
        print "</p>";
        print "</div>";
    }
    if (strlen($successMsg) > 0) {//Display success message if there is one
        print "<div class='alert-box success'>";
        print "<strong>Success!</strong>";
        print "<p>";
        print $successMsg;
        print "</p>";
        print "</div>";
    }
    ?>
    <div id="container">
        <div id="mainContent">
            <div>
                <p><img src="/resources/img/logoBanner.png" alt="KAT Banner"/></p><!-- Banner -->
                <hr />
                <?php include 'navigation.php'; ?><!-- Navigation Bar -->
                <p> Welcome to the Kenosha Area Transit Application manager.</p>
            </div>
            <div>
                <form>
                    <p>Filter</p>
                    <p>
                       <input type="text" id="searchFilter" placeholder="Location, Day, or Time" />  <!-- <input type="reset" value="Clear"> -->
                    </p>
                </form>

            </div>

            <?php
            if ($_SESSION['realm'] != 'View') {//Display the sticky box if user has View/Edit permissions or above 
                echo "<div id='reducedResolution'>";
                include 'hiddenEditBoxMin.php';
                echo "</div>";
            }
            
            include 'pagination.php';//Pagination for table
            
            ?> 
            <table id="minimalistTable" class="tableizer-table">
			<!-- ------------Table Headers (Columns)------------- -->
                    <thead class="tableizer-firstrow">
                        <th class="hidden">id</th>
                        <th>Location</th>
                        <th>Day</th>
                        <th>Time</th>
                        <th>Direction</th>
                    </thead>
			<!-- -----------End Table Headers (Columns)----------- -->		
                    <tbody> 
                        <?php
                        foreach ($routeArray as $data) {//Output route number data into table
                            if(strlen($data['time']) > 3){
                                $time = substr($data['time'],0,2) . ":" . substr($data['time'],2) .":00";
                            }else if (strlen($data['time']) == 3){
                               $time = "0" . substr($data['time'],0,1) . ":" . substr($data['time'],1) .":00";
                            }
			    else if (strlen($data['time']) == 2){
                               $time = "00:" . $data['time'] .":00";
                            }
			    else if (strlen($data['time']) == 1){
                               $time = "00:0" . $data['time'] .":00";
                            }
                            $human_time = date("g:iA", strtotime($time));
                            print "<tr class='clickable' onclick=\"populateForm('{$data['_id']}','{$data['location']}','{$data['day']}','{$data['time']}','{$data['direction']}')\">";
                            print "<td class='hidden'>{$data['_id']}</td>";
                            print "<td>{$data['location']}</td>";
                            print "<td>{$data['day']}</td>";
                            print "<td>{$human_time}</td>";
                            print "<td>{$data['direction']}</td>";
                            print "</tr>";
                        }
                        ?>
                    </tbody>
                </table>
            </div> <!-- Closes pagination div -->
        </div>
    </div>

    <div id="sideContent">
        <?php
        if ($_SESSION['realm'] != 'View') {//Display sticky box if user permission level is above 'View'
            echo "<div id='sticker' class = 'stick'>";
            include 'hiddenEditBox.php';
            echo "</div>";
        }
        ?> 
    </div>
    <div class="clear"></div>
</div>
<script>
    (function($) {
        $('#pagination').simplePagination();
    })(jQuery);
</script>
</body>
<div id="site-footer">Kenosha Area Transit Manager developed by UW-Parkside 2014</div><!-- Footer -->